package com.lmiot.xyclick.Util;

import android.os.Environment;
import android.text.TextUtils;
import android.util.Base64;
import com.google.gson.Gson;
import com.lmiot.xyclick.ActionDetailBean.DetailBean;
import com.lmiot.xyclick.Bean.ChangeAutoBean;
import com.lmiot.xyclick.Bean.SQL.ActionBean;
import com.lmiot.xyclick.Bean.SQL.ActionBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.FGBean;
import com.lmiot.xyclick.Bean.SQL.FGBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.FriendBean;
import com.lmiot.xyclick.Bean.SQL.FriendBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.GroupBean;
import com.lmiot.xyclick.Bean.SQL.GroupBeanSqlUtil;
import com.lmiot.xyclick.Util.LoopUtils;
import com.lmiot.xyclick.Util.ZipUtilOld;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.youyi.yyfilepickerlibrary.core.util.ConvertUtils;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import com.youyi.yyviewsdklibrary.ArrayGson;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import org.greenrobot.eventbus.EventBus;

public class FileUtils {
    private static Thread thread;
    private File file;

    public static void saveToLocalData(String str, String str2) {
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/XYClick/data", str);
            if (!file3.exists()) {
                new File(file3.getParent()).mkdirs();
                file3.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file3);
            fileOutputStream.write(str2.getBytes());
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void deleteDirWihtFile(File file2) {
        if (file2 != null && file2.exists() && file2.isDirectory()) {
            File[] listFiles = file2.listFiles();
            for (File file3 : listFiles) {
                if (file3.isFile()) {
                    file3.delete();
                } else if (file3.isDirectory()) {
                    deleteDirWihtFile(file3);
                }
            }
            file2.delete();
        }
    }

    public static String ReadTxtFile(String str) {
        File file2 = new File(str);
        String str2 = "";
        if (file2.isDirectory()) {
            LogUtil.d("TestFile", "The File doesn't not exist.");
        } else {
            try {
                FileInputStream fileInputStream = new FileInputStream(file2);
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
                while (true) {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        break;
                    }
                    str2 = str2 + readLine + "\n";
                }
                fileInputStream.close();
            } catch (FileNotFoundException unused) {
                LogUtil.d("TestFile", "The File doesn't not exist.");
            } catch (IOException e) {
                LogUtil.d("TestFile", e.getMessage());
            }
        }
        return str2;
    }

    public static void base64StringToFileAndReset01(String str, String str2) throws Exception {
        byte[] decode = Base64.decode(str, 0);
        FileOutputStream fileOutputStream = new FileOutputStream(str2);
        fileOutputStream.write(decode);
        fileOutputStream.close();
        File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick", "all.zip");
        if (!file2.exists()) {
            file2.createNewFile();
        }
        LoopUtils.unZipAll(file2, new LoopUtils.onUnZipFinishListener() {
            /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass1 */

            @Override // com.lmiot.xyclick.Util.LoopUtils.onUnZipFinishListener
            public void result(final boolean z) {
                FileUtils.resetLocalData(new OnBasicListener() {
                    /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass1.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                        if (z) {
                            ToastUtil.success("数据接收成功");
                        } else {
                            ToastUtil.err("数据接收失败");
                        }
                    }
                });
            }
        });
    }

    public static boolean copyDirectory(File file2, File file3) {
        if (!file2.isDirectory()) {
            return false;
        }
        if (!(file3.isDirectory() || file3.mkdirs())) {
            return false;
        }
        File[] listFiles = file2.listFiles();
        for (File file4 : listFiles) {
            File file5 = new File(file3, file4.getName());
            if (file4.isFile()) {
                if (!copyFile(file4, file5)) {
                    return false;
                }
            } else if (file4.isDirectory() && !copyDirectory(file4, file5)) {
                return false;
            }
        }
        return true;
    }

    public static boolean copyFile(File sourceFile, File targetFile) {
        if (sourceFile.getAbsolutePath().equals(targetFile.getAbsolutePath())) {
            return false;
        }
        FileInputStream input = null;
        BufferedInputStream inBuff = null;
        FileOutputStream output = null;
        BufferedOutputStream outBuff = null;
        try {
            // 新建文件输入流并对它进行缓冲
            input = new FileInputStream(sourceFile);
            inBuff = new BufferedInputStream(input);

            if (!targetFile.exists()) {
                targetFile.getParentFile().mkdirs();
                targetFile.createNewFile();
            }

            // 新建文件输出流并对它进行缓冲
            output = new FileOutputStream(targetFile);
            outBuff = new BufferedOutputStream(output);

            // 缓冲数组
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1) {
                outBuff.write(b, 0, len);
            }
            // 刷新此缓冲的输出流
            outBuff.flush();
            return true;

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                // 关闭流
                if (inBuff != null)
                    inBuff.close();
                if (outBuff != null)
                    outBuff.close();
                if (output != null)
                    output.close();
                if (input != null)
                    input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public static void saveIDFile(String str, String str2) {
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/ZData");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/ZData", str + ".jar");
            if (!file3.exists()) {
                new File(file3.getParent()).mkdirs();
                file3.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file3);
            fileOutputStream.write(str2.getBytes());
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static String readFileToString(File file) {
        StringBuilder fileContent = new StringBuilder("");
        if (file == null || !file.isFile()) {
            return null;
        }

        BufferedReader reader = null;
        try {
            InputStreamReader is = new InputStreamReader(new FileInputStream(file), "utf-8");
            reader = new BufferedReader(is);
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (!fileContent.toString().equals("")) {
                    fileContent.append("\r\n");
                }
                fileContent.append(line);
            }
            reader.close();
            return fileContent.toString();
        } catch (IOException e) {
            throw new RuntimeException("IOException occurred. ", e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException("IOException occurred. ", e);
                }
            }
        }
    }

    public static String fileToBase64String(String str) throws Exception {
        File file2 = new File(str);
        FileInputStream fileInputStream = new FileInputStream(file2);
        byte[] bArr = new byte[((int) file2.length())];
        fileInputStream.read(bArr);
        fileInputStream.close();
        return Base64.encodeToString(bArr, 2);
    }

    public static void base64StringToFile(String str, String str2) throws Exception {
        byte[] decode = Base64.decode(str, 0);
        FileOutputStream fileOutputStream = new FileOutputStream(str2);
        fileOutputStream.write(decode);
        fileOutputStream.close();
    }

    public static void base64StringToFileAndReset(String str, String str2) throws Exception {
        byte[] decode = Base64.decode(str, 0);
        FileOutputStream fileOutputStream = new FileOutputStream(str2);
        fileOutputStream.write(decode);
        fileOutputStream.close();
        File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick", "XYClick.zip");
        if (!file2.exists()) {
            file2.createNewFile();
        }
        LoopUtils.unZipBackFile(file2, new LoopUtils.onUnZipFinishListener() {
            /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass2 */

            @Override // com.lmiot.xyclick.Util.LoopUtils.onUnZipFinishListener
            public void result(final boolean z) {
                FileUtils.resetLocalData(new OnBasicListener() {
                    /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass2.AnonymousClass1 */

                    @Override // com.lmiot.xyclick.inteface.OnBasicListener
                    public void result(boolean z, String str) {
                        if (z) {
                            ToastUtil.success("云端数据恢复成功");
                            EventBus.getDefault().post(new ChangeAutoBean(""));
                            return;
                        }
                        ToastUtil.err("云端数据恢复失败");
                    }
                });
            }
        });
    }

    public static void resetLocalData(final OnBasicListener onBasicListener) {
        Thread r0 = new Thread() {
            /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass3 */

            public void run() {
                super.run();
                try {
                    FileUtils.checkFolder();
                    File file = new File(Environment.getExternalStorageDirectory() + "/XYClick");
                    File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp");
                    File[] listFiles = file.listFiles();
                    if (listFiles != null) {
                        for (File file3 : listFiles) {
                            if (!file3.isDirectory()) {
                                if (file3.getName().endsWith(DataUtil.FILE_FRIEND)) {
                                    FriendBeanSqlUtil.getInstance().addList(new ArrayGson().fromJsonList(FileUtils.readFileToString(file3), FriendBean.class));
                                }
                                if (file3.getName().endsWith(DataUtil.FILE_FG)) {
                                    FGBeanSqlUtil.getInstance().addList(new ArrayGson().fromJsonList(FileUtils.readFileToString(file3), FGBean.class));
                                } else if (file3.getName().endsWith(DataUtil.FILE_GROUP)) {
                                    GroupBeanSqlUtil.getInstance().addList(new ArrayGson().fromJsonList(FileUtils.readFileToString(file3), GroupBean.class));
                                } else if (file3.getName().endsWith(DataUtil.FILE_XYCLICK_DATA)) {
                                    ZipUtilOld.upZipFile00(file3, file2.getAbsolutePath());
                                }
                            }
                        }
                        File[] listFiles2 = file2.listFiles();
                        for (File file4 : listFiles2) {
                            if (file4.getName().endsWith(DataUtil.FILE_ACTION_DATA)) {
                                ActionBeanSqlUtil.getInstance().addList01(new ArrayGson().fromJsonList(FileUtils.readFileToString(file4), ActionBean.class));
                            }
                        }
                        for (File file5 : listFiles2) {
                            if (file5.getName().endsWith(DataUtil.FILE_AUTO_DATA)) {
                                AutoBeanSqlUtil.getInstance().addNoLocal((AutoBean) new Gson().fromJson(FileUtils.readFileToString(file5), AutoBean.class));
                            }
                        }
                    }
                    onBasicListener.result(true, "");
                } catch (Exception e) {
                    e.printStackTrace();
                    onBasicListener.result(false, "");
                }
            }
        };
        thread = r0;
        r0.start();
    }

    public static void saveToLocalData(final String str, final OnBasicListener onBasicListener) {
        checkFolder();
        try {
            new Thread() {
                /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass4 */

                public void run() {
                    DetailBean detailBean;
                    super.run();
                    try {
                        AutoBean searchByID = AutoBeanSqlUtil.getInstance().searchByID(str);
                        List<ActionBean> searchByID2 = ActionBeanSqlUtil.getInstance().searchByID(str);
                        if (searchByID != null) {
                            ArrayList arrayList = new ArrayList();
                            String saveXYFile = FileUtils.saveXYFile(searchByID.getAutoID() + "." + DataUtil.FILE_AUTO_DATA, new Gson().toJson(searchByID));
                            String saveXYFile2 = FileUtils.saveXYFile(searchByID.getAutoID() + "." + DataUtil.FILE_ACTION_DATA, new Gson().toJson(searchByID2));
                            arrayList.add(new File(saveXYFile));
                            arrayList.add(new File(saveXYFile2));
                            for (ActionBean actionBean : searchByID2) {
                                LogUtil.d("FileUtils图片", actionBean.getActionName());
                                String detail = actionBean.getDetail();
                                if (!TextUtils.isEmpty(detail) && (detailBean = (DetailBean) new ArrayGson().fromJson(detail, DetailBean.class)) != null) {
                                    String imgPath = detailBean.getImgPath();
                                    if (!TextUtils.isEmpty(imgPath)) {
                                        LogUtil.d("FileUtils图片", imgPath);
                                        arrayList.add(new File(imgPath));
                                    }
                                }
                            }
                            File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str + ".jpg");
                            if (file.isFile() && file.exists()) {
                                arrayList.add(file);
                            }
                            File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick/data", searchByID.getAutoID() + "." + DataUtil.FILE_XYCLICK_DATA);
                            if (!file2.exists()) {
                                file2.createNewFile();
                            }
                            ZipUtilOld.zipFiles(arrayList, file2.getAbsoluteFile(), new ZipUtilOld.ZipListener() {
                                /* class com.lmiot.xyclick.Util.FileUtils.AnonymousClass4.AnonymousClass1 */

                                @Override // com.lmiot.xyclick.Util.ZipUtilOld.ZipListener
                                public void result(boolean z) {
                                    if (z) {
                                        onBasicListener.result(true, "");
                                    } else {
                                        onBasicListener.result(false, "");
                                    }
                                }
                            });
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String saveXYFile(String str, String str2) {
        Exception e;
        File file2 = null;
        try {
            File file3 = new File(Environment.getExternalStorageDirectory() + "/XYClick");
            if (!file3.exists()) {
                file3.mkdirs();
            }
            File file4 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str);
            try {
                if (!file4.exists()) {
                    new File(file4.getParent()).mkdirs();
                    file4.createNewFile();
                }
                FileOutputStream fileOutputStream = new FileOutputStream(file4);
                fileOutputStream.write(str2.getBytes());
                fileOutputStream.close();
                return file4.getAbsolutePath();
            } catch (Exception e2) {
                e = e2;
                file2 = file4;
                try {
                    e.printStackTrace();
                    return file2.getAbsolutePath();
                } catch (Throwable unused) {
                    return file2.getAbsolutePath();
                }
            } catch (Throwable unused2) {
                file2 = file4;
                return file2.getAbsolutePath();
            }
        } catch (Exception e3) {
            e = e3;
            e.printStackTrace();
            return file2.getAbsolutePath();
        }
    }

    public static void delLocalData(String str) {
        DetailBean detailBean;
        try {
            for (ActionBean actionBean : ActionBeanSqlUtil.getInstance().searchByID(str)) {
                String detail = actionBean.getDetail();
                if (!TextUtils.isEmpty(detail) && (detailBean = (DetailBean) new ArrayGson().fromJson(detail, DetailBean.class)) != null) {
                    String imgPath = detailBean.getImgPath();
                    if (!TextUtils.isEmpty(imgPath)) {
                        File file2 = new File(imgPath);
                        if (file2.isFile() && file2.exists()) {
                            file2.delete();
                        }
                    }
                }
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str + ".jpg");
            if (file3.isFile() && file3.exists()) {
                file3.delete();
            }
            File file4 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str + "." + DataUtil.FILE_AUTO_DATA);
            if (file4.isFile() && file4.exists()) {
                file4.delete();
            }
            File file5 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str + "." + DataUtil.FILE_ACTION_DATA);
            if (file5.isFile() && file5.exists()) {
                file5.delete();
            }
            File file6 = new File(Environment.getExternalStorageDirectory() + "/XYClick/data", str + "." + DataUtil.FILE_XYCLICK_DATA);
            if (file6.isFile() && file6.exists()) {
                file6.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String encode(String str) {
        return Base64.encodeToString(str.getBytes(), 2);
    }

    public static int decode(String str) {
        try {
            return MathUtils.parseInt(new String(Base64.decode(str, 0)));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static String decodeString(String str) {
        try {
            return new String(Base64.decode(str, 0));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getFileSize(File file2) {
        if (!file2.exists() || !file2.isFile()) {
            return (!file2.exists() || !file2.isDirectory()) ? "0BT" : "";
        }
        long length = file2.length();
        DecimalFormat decimalFormat = new DecimalFormat("#.00");
        if (length < 1024) {
            DecimalFormat decimalFormat2 = new DecimalFormat("#");
            return decimalFormat2.format((double) length) + "B";
        } else if (length < 1048576) {
            return decimalFormat.format(((double) length) / 1024.0d) + "KB";
        } else if (length < ConvertUtils.GB) {
            return decimalFormat.format(((double) length) / 1048576.0d) + "MB";
        } else {
            return decimalFormat.format(((double) length) / 1.073741824E9d) + "GB";
        }
    }

    public static void saveFree(String str, int i) {
        String str2 = str + "#" + i;
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/Moon");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/Moon", "systemData.jar");
            if (!file3.exists()) {
                new File(file3.getParent()).mkdirs();
                file3.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file3);
            fileOutputStream.write(str2.getBytes());
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static int getFree(String str) {
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/Moon");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/Moon", "systemData.jar");
            if (!file3.exists()) {
                new File(file3.getParent()).mkdirs();
                file3.createNewFile();
            }
            String fileString = getFileString(file3);
            if (!TextUtils.isEmpty(fileString) && fileString.startsWith(str)) {
                return MathUtils.parseInt(fileString.split("#")[1]);
            }
            return 1000;
        } catch (Exception e) {
            e.printStackTrace();
            return 1000;
        }
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:38:0x0057 */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static String getFileString(File r5) {
        /*
            boolean r0 = r5.exists()
            r1 = 0
            if (r0 == 0) goto L_0x0063
            java.lang.String r0 = ""
            java.io.FileInputStream r2 = new java.io.FileInputStream     // Catch:{ Exception -> 0x0043, all -> 0x0041 }
            r2.<init>(r5)     // Catch:{ Exception -> 0x0043, all -> 0x0041 }
            java.io.BufferedReader r5 = new java.io.BufferedReader     // Catch:{ Exception -> 0x003c, all -> 0x0057 }
            java.io.InputStreamReader r3 = new java.io.InputStreamReader     // Catch:{ Exception -> 0x003c, all -> 0x0057 }
            r3.<init>(r2)     // Catch:{ Exception -> 0x003c, all -> 0x0057 }
            r5.<init>(r3)     // Catch:{ Exception -> 0x003c, all -> 0x0057 }
        L_0x0018:
            java.lang.String r1 = r5.readLine()     // Catch:{ Exception -> 0x003a }
            if (r1 == 0) goto L_0x002e
            java.lang.StringBuilder r3 = new java.lang.StringBuilder     // Catch:{ Exception -> 0x003a }
            r3.<init>()     // Catch:{ Exception -> 0x003a }
            r3.append(r0)     // Catch:{ Exception -> 0x003a }
            r3.append(r1)     // Catch:{ Exception -> 0x003a }
            java.lang.String r0 = r3.toString()     // Catch:{ Exception -> 0x003a }
            goto L_0x0018
        L_0x002e:
            r5.close()     // Catch:{ Exception -> 0x0035 }
            r2.close()     // Catch:{ Exception -> 0x0035 }
            return r0
        L_0x0035:
            r5 = move-exception
            r5.printStackTrace()     // Catch:{ all -> 0x0039 }
        L_0x0039:
            return r0
        L_0x003a:
            r1 = move-exception
            goto L_0x0047
        L_0x003c:
            r5 = move-exception
            r4 = r1
            r1 = r5
            r5 = r4
            goto L_0x0047
        L_0x0041:
            r2 = r1
            goto L_0x0057
        L_0x0043:
            r5 = move-exception
            r2 = r1
            r1 = r5
            r5 = r2
        L_0x0047:
            r1.printStackTrace()     // Catch:{ all -> 0x0056 }
            r5.close()     // Catch:{ Exception -> 0x0051 }
            r2.close()     // Catch:{ Exception -> 0x0051 }
            return r0
        L_0x0051:
            r5 = move-exception
            r5.printStackTrace()     // Catch:{ all -> 0x0055 }
        L_0x0055:
            return r0
        L_0x0056:
            r1 = r5
        L_0x0057:
            r1.close()     // Catch:{ Exception -> 0x005e }
            r2.close()     // Catch:{ Exception -> 0x005e }
            return r0
        L_0x005e:
            r5 = move-exception
            r5.printStackTrace()     // Catch:{ all -> 0x0062 }
        L_0x0062:
            return r0
        L_0x0063:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.lmiot.xyclick.Util.FileUtils.getFileString(java.io.File):java.lang.String");
    }

    public static void savePoint(String str, int i) {
        String str2 = str + "#" + i;
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/Moon");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/Moon", "systemDataPoint.jar");
            if (!file3.exists()) {
                new File(file3.getParent()).mkdirs();
                file3.createNewFile();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file3);
            fileOutputStream.write(str2.getBytes());
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static int getPoint(String str) {
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/Moon");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/Moon", "systemDataPoint.jar");
            if (!file3.exists()) {
                new File(file3.getParent()).mkdirs();
                file3.createNewFile();
            }
            String fileString = getFileString(file3);
            if (!TextUtils.isEmpty(fileString) && fileString.startsWith(str)) {
                return MathUtils.parseInt(fileString.split("#")[1]);
            }
            return 3;
        } catch (Exception e) {
            e.printStackTrace();
            return 3;
        }
    }

    public static void checkFolder() {
        if (YYPerUtils.hasSD()) {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/ZData");
            if (!file2.exists()) {
                file2.mkdirs();
            }
            File file3 = new File(Environment.getExternalStorageDirectory() + "/XYClick");
            if (!file3.exists()) {
                file3.mkdirs();
            }
            File file4 = new File(Environment.getExternalStorageDirectory() + "/XYClick/data");
            if (!file4.exists()) {
                file4.mkdirs();
            }
            File file5 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp");
            if (!file5.exists()) {
                file5.mkdirs();
            }
        }
    }
}
